<template>
    <div>

        <el-table :data="mrdiseaseList" style="width: 100%">
            <el-table-column label="ICD编码" prop="diseaseICD" />
            <el-table-column label="疾病名称" prop="diseaseName" />
            <el-table-column align="right">
            <template #header>
                <el-button size="small" @click="dialogVisible=true">
                   增加
                </el-button>
            </template>
            <template #default="scope">
                <el-button
                    size="small"
                    type="danger"
                    @click="handleDelete(scope.$index, scope.row)"
                >
                    删除
                </el-button>
            </template>
            </el-table-column>
        </el-table>

        <el-form :model="form" label-width="auto" style="max-width: 600px">

            <el-form-item label="注意事项">
                <el-input v-model="form.careful" />
            </el-form-item>
            <el-form-item label="断诊结果">
                <el-input v-model="form.diagnosis" />
            </el-form-item>
            <el-form-item label="理处意见">
                <el-input v-model="form.cure" />
            </el-form-item>
            <el-form-item>
                <el-button @click="saveRecord">保存</el-button><el-button>重置</el-button>
            </el-form-item>
        </el-form>
    </div>

    <el-dialog v-model="dialogVisible" title="添加西医诊断" width="500" draggable>
        <el-row>
            <el-col :span="4">
                <el-input v-model="dieaseQuery.diseaseICD" placeholder="请输入ICD搜索"/>
            </el-col>
            <el-col :span="4">
                <el-input v-model="dieaseQuery.diseaseName" placeholder="请输入疾病名称搜索"/>
            </el-col>
            <el-col :span="3">
                <el-button @click="searchDiease">搜索</el-button>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <el-table :data="dieaseList" stripe style="width: 100%">
                    <el-table-column type="selection"  width="55" />
                    <el-table-column prop="diseaseICD" label="ICD编码" width="180" />
                    <el-table-column prop="diseaseName" label="疾病名称" width="180" />
                </el-table>
            </el-col>
        </el-row>

    </el-dialog>
</template>

<script setup>
import httpRequest from '@/common';
import { ElMessage } from 'element-plus';
import {ref,getCurrentInstance, onMounted,defineProps, watch} from 'vue';

const {proxy} = getCurrentInstance();

//获取父组件传递的registerId  挂号id
const props = defineProps({
    rid:{
        type: Number,
        required: true
    }
});

const form = ref({

})

//  进入该页面说明病例已经创建出来了   先查询该病例
//进入组件就进行查询
const getRecordById = ()=>{

    httpRequest(
        proxy,
        'get',
        '/medicalrecord/register/'+props.rid,
        null,
        resultBean=>{
            form.value = resultBean.data;
            getMrDiseaseList();
        }
    )

}

const mrdiseaseList = ref([])

const getMrDiseaseList = ()=>{
    httpRequest(
        proxy,
        'get',
        '/recorddisease/mrid/'+form.value.id,
        null,
        resultBean=>{
            mrdiseaseList.value = resultBean.data;
        }
    )
}

const dieaseQuery = ref({})

const dieaseList = ref([])

const searchDiease = ()=>{
    httpRequest(
        proxy,
        'post',
        '/diease/conditions',
        dieaseQuery.value,
        resultBean=>{
            dieaseList.value = resultBean.data;
        }
    )
}

const dialogVisible = ref(false);

onMounted(()=>{
    // 在onMounted中直接获取props中父组件的传值会获取不到  设置一个定时任务
    setTimeout(()=>{
        getRecordById();

        
    },200);
})
</script>

<style>
</style>